package leetcode.datastructure.array;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;

/**
 * 乘法太多浪费计算时间
 */
public class Program55JumpGame {

    public Program55JumpGame() {
    }

    public boolean canJump(int[] nums) {
        int length = nums.length;
        if (length == 1) {
            return true;
        }

        int step = nums[0];
        if (step < 1) {
            return false;
        }
        for (int i = 1; i < length - 1; i++) {
            step = Math.max(--step, nums[i]);
            if (step < 1) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Program55JumpGame myStack = new Program55JumpGame();
        int[] prices2 = {2,3,1,1,4};
        System.out.println(myStack.canJump(prices2));
        int[] prices1 = {3,2,1,0,4};
        System.out.println(myStack.canJump(prices1));
        int[] prices = {0,1};
        System.out.println(myStack.canJump(prices));
        int[] prices3 = {2,0,0};
        System.out.println(myStack.canJump(prices3));
    }
}
